$(function () {
    $('.am-header-title').text('注册');

    function showalert(txt) {
       alert(txt)
    }
    $("#head").attr("src", '../../img/head-01.png');
    $('input[name="sex"]').on('change',function(){
        var sexs = $("input[name =sex]:checked").val();
        if(sexs=="1" || sexs==""){
            $("#head").attr("src", '../../img/head-02.png');
        }else{
            $("#head").attr("src", '../../img/head-01.png');
        }
    });



    $("#regsubmit").click(function () {
        var sex = $("input[name =sex]:checked").val();
        var account = $("#account").val();
        var password = $("#password").val();
        var confirmPassword = $("#password-confirm").val();
        var birthday = $("#birthday").val();
        var address = $("#address").val();
        var nickname = $("#nickname").val();
        var inviteCode = $("#inviteCode").val();
        var superModal = $("#modal").val();
        if (sex == "" || sex == undefined) {
            showalert("请选择账号类型");
            return false;
        }
        if (account == "") {
            showalert("账号不能为空");
            return false;
        }


        

        if (nickname == "") {
            showalert("昵称不能为空");
            return false;
        }

        if (password == "") {
            showalert("密码不能为空");
            return false;
        }

        if (confirmPassword == "") {
            showalert("确认密码不能为空");
            return false;
        }
        if (password != confirmPassword) {
            showalert("两次输入的密码不一致");
            return false;
        }

        if (birthday == "") {
            showalert("生日不能为空");
            return false;
        }

        if (superModal == "") {
            showalert("请选择与您相似的模特");
            return false;
        }


        var url = "/h5/doRegister";

        $.ajax({
            type: 'POST',
            dataType: 'json',
            url: url,
            data: {
                sex: sex,
                account: account,
                password: password,
                birthday: birthday,
                address: address,
                nickname: nickname,
                inviteCode: inviteCode,
                superModal: superModal
            },
            success: function (res) {
                if (res.code == "000000") {
                    localStorage.setItem("userTmp", JSON.stringify(res.user));
                    window.location.href = "../index.jsp";
                } else {
                    showalert(res.msg);
                }

            },
            error: function (res) {

            }
        });


    });

});

